package pharao.client.views.navigation;

import hmvc4gwt.client.event.IHmvcEvent;
import hmvc4gwt.framework.client.controller.NavigationController;
import hmvc4gwt.framework.client.events.CloseViewEvent;

import pharao.client.views.game.GameController;
import pharao.client.views.game.GameView;
import pharao.client.views.game.login.events.ShowLoginViewEvent;
import pharao.client.views.game.registrierung.events.ShowRegistrierungsViewEvent;
import pharao.client.views.index.IndexController;
import pharao.client.views.index.IndexModel;
import pharao.client.views.index.IndexView;
import pharao.client.views.index.events.ShowIndexViewEvent;
import pharao.client.views.navigation.events.AddGameNavigationEvent;

public class PharaoNavigationController extends NavigationController {

	

	public void initImpl() {
		register(AddGameNavigationEvent.class, this);
	}

	public Class getClassOfObject() {
		return PharaoNavigationController.class;
	}

	public void handleEventImpl(IHmvcEvent event) {
	}

	public void onHistoryChanged(String historyToken) {

		if (historyToken.equals(PharaoNavigationModel.linkLogin)) {
			fireEvent(new CloseViewEvent(), false, true, true);
			
			addChildComponent(new GameController(), new GameView());
			fireEvent(new ShowLoginViewEvent(), false, false, true);
			

		} else if (historyToken.equals(PharaoNavigationModel.linkRegister)) {

			fireEvent(new CloseViewEvent(), false, true, true);

			addChildComponent(new GameController(), new GameView());
			fireEvent(new ShowRegistrierungsViewEvent(), false, false, true);
			

		} else if (historyToken.equals(PharaoNavigationModel.linkIndex)) {

			fireEvent(new CloseViewEvent(), false, true, true);

			/*
			 * Startseite anzeigen
			 */
			addChildComponent(new IndexController(), new IndexModel(),
					new IndexView());
			fireEvent(new ShowIndexViewEvent(), false, false, true);

		}
	}

	public void terminate() {
		// TODO Auto-generated method stub

	}
}
